package com.ftn;

import java.awt.*;

/**
 * User: Jack Fu
 * Date: 2024/9/6
 * Time: 14:05
 * To change this template use File | Settings | File Templates.
 * Description:
 */
public class Boss2Obj extends GameObj{

    int health = 20;

    @Override
    public void paintSelf(Graphics g) {
        if (y < 100) { // 当未完整出现在窗口中时，一直向下移动
            y += 2;
        } else {
            // 只移动x轴
            x += speed;
            if (x > 400 || x < 0) {// 碰到左右边窗口，速度取反
                speed = -speed;
            }
        }

        // 与飞机子弹碰撞20次后，消失
        for (ShellObj shellObj : GameUtils.shellObjs) {
            if (this.getRec().intersects(shellObj.getRec())) {
                health--;
                if (health <= 0) {
                    // 添加爆炸对象
                    ExplodeObj explodeObj = new ExplodeObj(this.getX(), this.getY());
                    GameUtils.explodeObjs.add(explodeObj);
                    GameUtils.removeObjs.add(explodeObj);

                    // 添加补给
                    GiftObj  giftObj = new GiftObj(this.x, this.y);
                    GameUtils.giftObjs.add(giftObj);
                    GameUtils.gameObjs.add(giftObj);

                    // 现将元素移除到界面之外
                    shellObj.setX(-6500);
                    this.setX(-6500);

                    GameUtils.removeObjs.add(this);
                    GameWin.score += 50;
                } else {
                    // 现将元素移除到界面之外
                    shellObj.setX(-6500);
                }
                GameUtils.removeObjs.add(shellObj);
            }
        }

        super.paintSelf(g);
    }

    @Override
    public Rectangle getRec() {
        return super.getRec();
    }

    public Boss2Obj() {
        setImage(GameUtils.boss2Image);
        setX(200);
        setY(-300);
        setWidth(200);
        setHeight(200);
        setSpeed(3);
    }

    public Boss2Obj(GameWin gameWin) {
        setGameWin(gameWin);
        setImage(GameUtils.boss2Image);
        setX(200);
        setY(-300);
        setWidth(200);
        setHeight(200);
        setSpeed(2);
    }

    public Boss2Obj(int x, int y) {
        super(x, y);
    }

    public Boss2Obj(int x, int y, int width, int height, Image image, int speed, GameWin gameWin) {
        super(x, y, width, height, image, speed, gameWin);
    }

    public Boss2Obj(int x, int y, Image image, int speed) {
        super(x, y, image, speed);
    }
}
